<?php


class DB
{
  function __construct($host,$dbname,$user,$pass)
  {
      try{
          $this->db = new PDO("mysql:dbname={$dbname};host={$host}",$user,$pass,array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8"));
      }catch (PDOException $e){
          die($e->getMessage());
      }

  }
  function query(){
      $args = func_get_args();
      $query = $args[0];
      $others = array_splice($args,1,count($args));
      $r = $this->db->prepare($query);
      $r->execute($others);
      $info = $r->errorInfo();
      if($info[0]=='00000'){
        $result = $r->fetchAll(PDO::FETCH_ASSOC);
        return $result;
      }else{
          die($info[2]);
      }
  }
}